

<template>

  <div>

    <div v-for="(item,index) in list">
      <div class="flex" style="margin: 0.6rem; flex-direction: column;" >
        <div style="font-size: 1.2rem">{{item.title}}？</div>
        <div class="flex-row" style="justify-content: space-between; width: 100%;  height: 3rem;line-height: 3rem;">
          <div style="color: #7b7a7a">{{item.name}} 第{{item.stage}}课</div>
          <div @click="continueClick(index)" style="background-color: #900984; height: 2rem; line-height: 2rem;margin-top: 0.5rem; padding: 0.1rem 0.6rem; box-sizing: border-box; color: white">继续学习</div>
        </div>
        <div style="color: #7b7a7a;font-size: 0.9rem;">上次学习：{{item.last_time_date}}</div>
      </div>
      <div style="width: 100%; height: 0.01rem; background-color: #e4e4e5; border-top:1px #cfcfcf solid;"></div>
    </div>

    <div v-if="list.length == 0" style="margin: 1rem auto; width: 50%; text-align: center; color:#7b7a7a ">暂无更多内容！</div>  

  </div>

</template>

<script>

import { base64} from 'vux'

export default {

  components: {
   base64
  },
  data () {
    return {
      none: true,
      list:'',
      lesson_id:'',
      section_id:'',
      cate_id:'',
      access_token:''
     
    }
  },
  methods:{
     
     
    //获取详情
    getDetail(){
    	
	    	this.$store.commit('updateLoadingStatus',true);
	    	
	    	this.$http.get(this.$store.state.api + 'index/learning-history&access_token=' + this.access_token)
		    .then((response) => {
		    		
		    console.log(response)
				
				if(response.body.code == 0) {
					
					this.list = response.body.data
					
				} else {
					
				}
					
				
				this.$store.commit('updateLoadingStatus',false);	
				
			}, (response) => {
	             
	            
	            
			});
    
    },
    
    //继续学习
    continueClick(index){
    	
    	this.cate_id = this.list[index].cate_id
    	this.lesson_id = this.list[index].lesson_id
    	this.section_id = this.list[index].section_id
    	
    	if(this.cate_id == 1){
    		
    		this.$router.push({ path: '/freeDetail',name:'freeDetail',params:{lesson_id:this.lesson_id,section_id:this.section_id}});
    		
    	}else if(this.cate_id == 2){
    		
    		this.$router.push({ path: '/classDetail',name:'classDetail',params:{lesson_id:this.lesson_id,section_id:this.section_id}});
    		
    	}else if(this.cate_id == 3){
    		
    		this.$router.push({ path: '/moviesDetail',name:'moviesDetail',params:{lesson_id:this.lesson_id,section_id:this.section_id}});
    		
    	}
    	
    },
    
    //获取地址栏信息
		getUrlStr(name){
	      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
	      if(reg.test(window.location.href)){
	        return unescape(RegExp.$2.replace(/\+/g," "))
	      }
	      return undefined
	    },	
    
  },
  
  mounted() {
  	
  	 var access_token = this.getUrlStr('access_token');
           var parentId = this.getUrlStr('parent_id');
           
            if(parentId == undefined){
              parentId = 0;
           }
           
           var uid = this.getUrlStr('uid');
           
           if(parentId.toString().indexOf('?') > 0){
           	 parentId = parentId.split('?')[0];
           }
           
           var locurl = location.href;
           locurl = base64.encode(locurl.split('?')[0]);
           
       
           if(access_token != undefined){
         
              localStorage.setItem("access_token",access_token); 
              localStorage.setItem("parent_id",this.getUrlStr('uid'));


           }
           
            if(localStorage.getItem('access_token') != null){
         
              this.$root.registerjudge();
              this.$root.getShare();
              
            }else{
            	
        	  this.$root.gotoWechat(locurl,parentId);
            }
           
    	   this.access_token = localStorage.getItem('access_token');

    this.getDetail();

  },

  beforeMount () {

    this.index=this.$store.state.selectIndex;

  }
  

}



</script>


<style lang="less" scoped>

  .active{
    color: white;
  }


</style>
